/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fullalbum.dao;

import fullalbum.TransactionDAO;
import fullalbum.bean.Album;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author leoomoreira
 */
public class AlbumDAO {

    public Album getById(Integer id) {
        String sqlAlbum = "select id, name, user_id from album where id = " + id + "";

        Album album = new Album();
        TransactionDAO dao = new TransactionDAO();

        ResultSet resultSetAlbum = dao.executeQuery(sqlAlbum);
        
        try {
            while (resultSetAlbum != null && resultSetAlbum.next()) {
                album.setId(Integer.parseInt(resultSetAlbum.getString("id")));
                album.setName(resultSetAlbum.getString("name"));
                album.setUserId(Integer.parseInt(resultSetAlbum.getString("user_id")));
            }
        } catch (SQLException ex) {
            Logger.getLogger(AlbumDAO.class.getName()).log(Level.SEVERE, null, ex);
        }

        dao.commit();
        dao.close();
        return album;
    }
}
